package com.scott.flyweight.lesson01;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元对象工厂
 */
public class FlyweightFactory {
	
	//用Map缓存多个 享元对象
	private Map<String,Flyweight> map = new HashMap<String,Flyweight>();
	
	public Flyweight getFlyweight(String key){
		Flyweight flyweight= map.get(key);
		
		if(flyweight==null){
			flyweight = new ConcreteFlyweight(key);
			//把新的对象增加到缓存中...
			map.put(key, flyweight);
		}
		return flyweight;
	}

}
